package com.zou.controller.proscenium;

import com.zou.pojo.Article;
import com.zou.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class NewController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("/proscenium/new/{id}")
    public String newArticle(@PathVariable("id") String id, Model model) {
        Article article = articleService.queryArticleById(id);
        // 去除点击量前面的0
        article.setArticlePageViews(String.valueOf(
                Integer.valueOf(article.getArticlePageViews())
        ));
        model.addAttribute("article", article);
        // 调用异步任务将当前文章的浏览量加一
        articleService.articlePageViewsPlusOne(id);
        return "proscenium/new.html";
    }
}
